package com.jy.controller;


import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.jy.common.ResultInfo;
import com.jy.entity.Type;
import com.jy.service.ITypeService;
import com.jy.vo.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 车位类型表 前端控制器
 * </p>
 *
 * @author xiexingxin
 * @since 2022-11-15
 */
@RestController
@RequestMapping("/type")
public class TypeController {

    @Autowired
    private ITypeService iTypeService;

    /**
     * 获取车位类型所以信息
     * @return
     */
    @GetMapping("/selallcarporttype")
    public Result selAllcarportType(){
        List<Type> list = iTypeService.list();
        return list.size() > 0 ? Result.success(ResultInfo.SELECT_SUCCESS,list) : Result.failed(ResultInfo.SELECT_FAIL);
    }

    /**
     * 添加车位类型
     * @param type
     * @return
     */
    @PostMapping("/addcarporttype")
    public Result addCarportType(@RequestBody Type type){
        boolean save = iTypeService.save(type);
        return save == true ? Result.success(ResultInfo.ADD_SUCCESS,save) : Result.failed(ResultInfo.ADD_FAIL);
    }

    /**
     * 根据typeId删除车位类型
     * @param typeId
     * @return
     */
    @DeleteMapping("/delcarporttype")
    public Result delCarportType(Integer typeId){
        boolean remove = iTypeService.removeById(typeId);
        return remove == true ? Result.success(ResultInfo.DELETE_SUCCESS,remove) : Result.failed(ResultInfo.DELETE_FAIL);
    }

    /**
     * 根据ID修改车位类型
     * @param type
     * @return
     */
    @PostMapping("/updcarporttype")
    public Result updCarportType(@RequestBody Type type){
        UpdateWrapper updateWrapper = new UpdateWrapper();
        updateWrapper.eq("typeId",type.getTypeId());
        updateWrapper.set("typeName",type.getTypeName());
        boolean update = iTypeService.update(updateWrapper);
        return update == true ? Result.success(ResultInfo.UPDATE_SUCCESS,update) : Result.failed(ResultInfo.UPDATE_FAIL);
    }
    
}
